// C:\Documents and Settings\Administrator\My Documents\VCPP projects\090109a_SwordBible\src\CrossLinksMgr.cpp : implementation file
//

#include "stdafx.h"
#include "SwordBible.h"
#include "CrossLinksMgr.h"
#include "SwordBibleDoc.h"
#include "BiblePage.h"

// CCrossLinksMgr dialog

IMPLEMENT_DYNAMIC(CCrossLinksMgr, CDialog)

CCrossLinksMgr::CCrossLinksMgr(CWnd* pParent /*=NULL*/)
	: CDialog(CCrossLinksMgr::IDD, pParent)
{

}

CCrossLinksMgr::~CCrossLinksMgr()
{
}

void CCrossLinksMgr::DoDataExchange(CDataExchange* pDX)
{
  CDialog::DoDataExchange(pDX);
  DDX_Control(pDX, IDC_COMBO_BIBLE, m_comboBibles);
  DDX_Control(pDX, IDC_COMBO_GREEK, m_comboGreek);
  DDX_Control(pDX, IDC_COMBO_HEBREW, m_comboHebrew);
  DDX_Control(pDX, IDC_COMBO_DICTIONARY, m_comboDict);
  DDX_Control(pDX, IDC_COMBO_MORPH, m_comboMorph);
}


BEGIN_MESSAGE_MAP(CCrossLinksMgr, CDialog)
  ON_BN_CLICKED(IDOK, &CCrossLinksMgr::OnOk)
END_MESSAGE_MAP()


// CCrossLinksMgr message handlers

BOOL CCrossLinksMgr::OnInitDialog()
{
  CDialog::OnInitDialog();

  
  SetWindowText(SBLocalize::ResourceSet[ITEM_CROSSLINKSHEADING].menuStr);

  SetXRef();

  SetDict();

  SetGreek();

  SetHebrew();

  SetMorph();

  return TRUE;  // return TRUE unless you set the focus to a control
  // EXCEPTION: OCX Property Pages should return FALSE
}

void CCrossLinksMgr::SetXRef()
{
  if(CSwordBibleDoc::pXrefModuleActive == NULL || CSwordBibleDoc::numBiblesAvailable == 0) {
	  m_comboBibles.AddString(_T("Not Installed"));
	  m_comboBibles.SetCurSel(0);
	  return;
  }

  CString n1 = (CString) CSwordBibleDoc::pXrefModuleActive->Name();

  // fill in the strings for different bible versions
  for(int i = 0; i < CSwordBibleDoc::numBiblesAvailable; i++) {
		if(CSwordBibleDoc::pRTFBibleModule[i] != NULL) 		{
			m_comboBibles.AddString( (CString) CSwordBibleDoc::pRTFBibleModule[i]->Name()   );
     }
  }

  m_comboBibles.SelectString(-1,n1);

}

void CCrossLinksMgr::SetDict()
{
  if(CSwordBibleDoc::pDictModuleActive == NULL || CSwordBibleDoc::numDictAvailable == 0)  {
	  m_comboDict.AddString(_T("Not Installed"));
	  m_comboDict.SetCurSel(0);
	  return;
  }

   CString n1 = (CString) CSwordBibleDoc::pDictModuleActive->Name();

  // fill in the strings for different dictionary versions
  for(int i = 0; i < CSwordBibleDoc::numDictAvailable; i++) {
		if(CSwordBibleDoc::pRTFDictModule[i] != NULL) 		{
			m_comboDict.AddString( (CString) CSwordBibleDoc::pRTFDictModule[i]->Name()   );
     }
  }

  m_comboDict.SelectString(-1,n1);

}

void CCrossLinksMgr::SetGreek()
{

  if(CBiblePage::pGreek == NULL || CSwordBibleDoc::numDictAvailable == 0) {
	  m_comboGreek.AddString(_T("Not Installed"));
	  m_comboGreek.SetCurSel(0);
	  return;
  }

  CString n1 = (CString) CBiblePage::pGreek->Name();

  // find if the strong's greek module is installed.
  for(int i = 0; i < CSwordBibleDoc::numDictAvailable; i++) {
    if(CSwordBibleDoc::pRTFDictModule[i] != NULL) {

      CString n2 = (CString) CSwordBibleDoc::pRTFDictModule[i]->Name();
      m_comboGreek.AddString(n2);
    
    }
  }

  m_comboGreek.SelectString(-1, n1);  
    
}

void CCrossLinksMgr::SetHebrew()
{
    if(CBiblePage::pHebrew == NULL || CSwordBibleDoc::numDictAvailable == 0) {
	  m_comboHebrew.AddString(_T("Not Installed"));
	  m_comboHebrew.SetCurSel(0);
	  return;
  }

  CString n1 = (CString) CBiblePage::pHebrew->Name();

  // find if the strong's Hebrew module is installed.
  for(int i = 0; i < CSwordBibleDoc::numDictAvailable; i++) {
    if(CSwordBibleDoc::pRTFDictModule[i] != NULL) {

      CString n2 = (CString) CSwordBibleDoc::pRTFDictModule[i]->Name();
      m_comboHebrew.AddString(n2);
     }
  }

  m_comboHebrew.SelectString(-1, n1);  
    

}


void CCrossLinksMgr::SetMorph()
{
    if(CBiblePage::pMorph == NULL || CSwordBibleDoc::numDictAvailable == 0) {
	  m_comboMorph.AddString(_T("Not Installed"));
	  m_comboMorph.SetCurSel(0);
	  return;
  }

  CString n1 = (CString) CBiblePage::pMorph->Name();

  // find if the strong's Hebrew module is installed.
  for(int i = 0; i < CSwordBibleDoc::numDictAvailable; i++) {
    if(CSwordBibleDoc::pRTFDictModule[i] != NULL) {

      CString n2 = (CString) CSwordBibleDoc::pRTFDictModule[i]->Name();
	  m_comboMorph.AddString(n2);
 

    }
  }

  m_comboMorph.SelectString(-1, n1);  
    

}



void CCrossLinksMgr::SaveGreek()
{
  if(CSwordBibleDoc::numDictAvailable == 0) return;

  int sel = m_comboGreek.GetCurSel();

  if(sel < 0) return;

  CString n1 = _T("");
  m_comboGreek.GetLBText(sel, n1);
     
  for(int i = 0; i < CSwordBibleDoc::numDictAvailable; i++) {
    if(CSwordBibleDoc::pRTFDictModule[i] != NULL) {
      
      CString n2 = (CString) CSwordBibleDoc::pRTFDictModule[i]->Name();
      if(n1 == n2) {
        CBiblePage::pGreek = CSwordBibleDoc::pRTFDictModule[i];

      	// write the active module for cross-ref tooltips to the registry
		    AfxGetApp()->WriteProfileString(_T("Tags"), _T("GreekModule"), n2);
      }
    }
  }

}

void CCrossLinksMgr::SaveHebrew()
{
  if(CSwordBibleDoc::numDictAvailable == 0) return;

  int sel = m_comboHebrew.GetCurSel();

  if(sel < 0) return;

  CString n1 = _T("");
  m_comboHebrew.GetLBText(sel, n1);
     
  for(int i = 0; i < CSwordBibleDoc::numDictAvailable; i++) {
    if(CSwordBibleDoc::pRTFDictModule[i] != NULL) {
      
      CString n2 = (CString) CSwordBibleDoc::pRTFDictModule[i]->Name();
      if(n1 == n2) {
        CBiblePage::pHebrew = CSwordBibleDoc::pRTFDictModule[i];

      	// write the active module for cross-ref tooltips to the registry
		    AfxGetApp()->WriteProfileString(_T("Tags"), _T("HebrewModule"), n2);
      }
    }
  }

}




void CCrossLinksMgr::SaveMorph()
{
  if(CSwordBibleDoc::numDictAvailable == 0) return;

  int sel = m_comboMorph.GetCurSel();

  if(sel < 0) return;

  CString n1 = _T("");
  m_comboMorph.GetLBText(sel, n1);
     
  for(int i = 0; i < CSwordBibleDoc::numDictAvailable; i++) {
    if(CSwordBibleDoc::pRTFDictModule[i] != NULL) {
      
      CString n2 = (CString) CSwordBibleDoc::pRTFDictModule[i]->Name();
      if(n1 == n2) {
		  CBiblePage::pMorph = CSwordBibleDoc::pRTFDictModule[i];

      	// write the active module for cross-ref tooltips to the registry
		    AfxGetApp()->WriteProfileString(_T("Tags"), _T("MorphModule"), n2);
      }
    }
  }

}



void CCrossLinksMgr::SaveXRef()
{

  if(CSwordBibleDoc::numBiblesAvailable == 0) return;

  int sel = m_comboBibles.GetCurSel();

  if(sel < 0) return;

  CString n1 = _T("");
  m_comboBibles.GetLBText(sel, n1);
     
  for(int i = 0; i < CSwordBibleDoc::numBiblesAvailable; i++) {
    if(CSwordBibleDoc::pRTFBibleModule[i] != NULL) {
      
      CString n2 = (CString) CSwordBibleDoc::pRTFBibleModule[i]->Name();
      if(n1 == n2) {
      CSwordBibleDoc::pXrefModuleActive = CSwordBibleDoc::pRTFBibleModule[i];

      	// write the active module for cross-ref tooltips to the registry
		    AfxGetApp()->WriteProfileString(_T("Tags"), _T("XrefModule"), n2);
      }
    }
  }
}

void CCrossLinksMgr::SaveDict()
{
  if(CSwordBibleDoc::numDictAvailable == 0) return;

  int sel = m_comboDict.GetCurSel();

  if(sel < 0) return;

  CString n1 = _T("");
  m_comboDict.GetLBText(sel, n1);
     
  for(int i = 0; i < CSwordBibleDoc::numDictAvailable; i++) {
    if(CSwordBibleDoc::pRTFDictModule[i] != NULL) {
      
      CString n2 = (CString) CSwordBibleDoc::pRTFDictModule[i]->Name();
      if(n1 == n2) {
        CSwordBibleDoc::pDictModuleActive = CSwordBibleDoc::pRTFDictModule[i];

      	// write the active module for cross-ref tooltips to the registry
		    AfxGetApp()->WriteProfileString(_T("Tags"), _T("DictModule"), n2);
      }
    }
  }



}

void CCrossLinksMgr::OnOk()
{

  SaveXRef();

  SaveGreek();

  SaveHebrew();

  SaveDict();

  SaveMorph();

  OnOK();


}
